<template>
  <div>
    <el-button type="danger" size="mini" @click="dialogVisible = true">
      <i class="el-icon-delete"></i>
    </el-button>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span>确定要删除帖子吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="deletePost">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { deletePostById } from "@/api/post/post";

export default {
  name: "DeletePost",
  inject: ['reload'],
  props: {
    postId: Number
  },
  data() {
    return {
      dialogVisible: false
    }
  },
  methods: {
    deletePost() {
      deletePostById({
        postId: Number(this.postId)
      }).then(res => {
        if (res.data.code === 200) {
          setTimeout(() => {
            this.reload()
          }, 3000)
          this.dialogVisible = false
          this.$message.success(res.data.message)
        } else {
          // this.$message.error(res.data.message)
        }
      })
    }
  }
}
</script>
